//
//  SendSuggestViewController.m
//  Lucky28
//
//  Created by zr on 2018/8/2.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "SendSuggestViewController.h"

@interface SendSuggestViewController () <UITextViewDelegate>

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UITextView * textView;
@property (nonatomic, weak)UIButton * finishButton;

@end

@implementation SendSuggestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    self.view.backgroundColor = ColorWithRGB(0xE8E8E8);
    self.view.backgroundColor = ColorWithRGB(0xF4F5F6);
    
    [self setupNav];
    [self setupUI];
}

- (void)setupNav{
    
    self.title = @"意见反馈";

//    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back(1)"] style:UIBarButtonItemStylePlain target:nil action:nil];
//    
//    self.navigationItem.backBarButtonItem = backItem;
}


- (void)setupUI{
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"亲，感谢您为我们提供宝贵的建议，我们会认真考虑的哟!";
    titleLabel.textColor = [UIColor lightGrayColor];
    titleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.view addSubview:self.titleLabel];
    
    
    // 创建textView
    UITextView *textView =[[UITextView alloc]initWithFrame:CGRectMake(15 * SCREENH6,kStatusBarHeight + kNavHeight + 40 * SCREENH6,kScreenW - 30 * SCREENH6,300 * SCREENH6)];
    textView.backgroundColor= ZRWhiteColor;
    textView.text = @"可以在这儿写下想说的话~";
    textView.font = [UIFont systemFontOfSize:14 * SCREENH6];
    textView.textColor = ColorWithRGB(0xbebebe);
    textView.delegate = self;
    textView.layer.cornerRadius = 5;
    textView.layer.borderColor = [[UIColor grayColor] CGColor];
    textView.layer.borderWidth = 1 * SCREENH6;
    textView.layer.masksToBounds = YES;
    
    self.textView = textView;
    [self.view addSubview:self.textView];
    
    
    UIButton * finishButton = [UIButton new];
    
    [finishButton setTitle:@"提交" forState:UIControlStateNormal];
    [finishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [finishButton setBackgroundColor:ZRBlackColor];
    [finishButton addTarget:self action:@selector(clickFinishButton) forControlEvents:UIControlEventTouchUpInside];
    finishButton.titleLabel.font = [UIFont systemFontOfSize:17 * SCREENH6];
    
    self.finishButton = finishButton;
    
    [self.view addSubview:self.finishButton];
}


- (void)viewDidLayoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.view).offset(kStatusBarHeight + kNavHeight + 10 * SCREENH6);
    }];
    
    
    [self.finishButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(40 * SCREENH6);
        make.trailing.mas_equalTo(self.view).offset(-40 * SCREENH6);
        make.bottom.mas_equalTo(self.view).offset(-190 * SCREENH6);
        make.height.mas_equalTo(40 * SCREENH6);
    }];
}


- (void)clickFinishButton{
    
    [[ZRNetworkTool sharedTool] userFeedBackmWithConent:self.textView.text ResultWithBlock:^(BOOL success, id responseData) {
        
        if (success) {
            
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                           message:@"感谢您的反馈！"
                                                                    preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                  handler:^(UIAlertAction * action) {
                                                                      
                                                                      [self.navigationController popViewControllerAnimated:YES];
                                                                  }];
            
            [alert addAction:defaultAction];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
}


#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    
    if(textView.text.length < 1){
        textView.text = @"可以在这儿写下想说的话~";
        textView.textColor = ColorWithRGB(0xbebebe);
    }else{
        
        [textView resignFirstResponder];
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"可以在这儿写下想说的话~"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.textView resignFirstResponder];
//    [self.textView endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
